using CodeGeneratorLibrary;
using Templates.Interfaces;

namespace Templates.Bitrix.Database
{
	public partial class SPComunication : ICodeFile
	{
		private Table _table;

		public void BindData(Table table)
		{
			_table = table;
		}
		public string EntityName { get { return _table.EntityName; } }

		public string ClassName
		{
			get { return string.Format("{0}", _table.EntityName); } 
		}
		public string ruName { get; set; }

		public Options Options { get { return CodeGeneratorLibrary.Options.Factory; } }
		public string ProcName { get { return string.Format("{0}", ClassName); } }

		public string ProjectFileType { get { return "Compile"; } }
		public string ProjectFilePath { get { return @"DataLayer\Model\" + ClassName + ".partial.cs"; } }
		public string ProjFullName { get { return @"D:\e\CodeGenerator\ws.nafania\ws.nafania.csproj"; } }
	}
	
	public static class ReaderExtentions
	{
		public static string ToReaderName(this string type, bool isNullable)
		{
			var temp = type.ToSqlType();
			return string.Format("Get{0}{1}", temp, (isNullable ? "OrNull" : ""));
		}

		public static string ToSqlType(this string sharpType)
		{
			var temp = sharpType;
			switch(sharpType)
			{
				case "string":
					temp = "String";
					break;
				case "int":
					temp = "Int32";
					break;
				case "byte":
					temp = "Byte";
					break;
				case "bool":
					temp = "Boolean";
					break;
				case "float":
					temp = "Float";
					break;
				case "long":
					temp = "Int64";
					break;
				default:
					break;
			}
			return temp;
		}

		public static string UppercaseFirst(this string s)
		{
			// Check for empty string.
			if (string.IsNullOrEmpty(s))
			{
				return string.Empty;
			}
			// Return char and concat substring.
			return char.ToUpper(s[0]) + s.Substring(1);
		}
		public static string LowercaseFirst(this string s)
		{
			// Check for empty string.
			if (string.IsNullOrEmpty(s))
			{
				return string.Empty;
			}
			// Return char and concat substring.
			return char.ToLower(s[0]) + s.Substring(1);
		}
	}
}